package com.qzsoft.zhjd.laboratory.modules.laboratorymechanics.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.laboratory.modules.laboratorymechanics.dto.LaboratoryMechanicsPressMachineDto;
import com.qzsoft.zhjd.laboratory.modules.laboratorymechanics.service.LaboratoryMechanicsPressMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author cuiwenlong
 * @ClassName LaboratoryMechanicsPressMachineController
 * @Description 压力机
 * @since 2023-07-10
 */
@RestController
@RequestMapping("/api/laboratoryMechanicsPressMachine")
public class LaboratoryMechanicsPressMachineController {

    @Autowired
    private LaboratoryMechanicsPressMachineService service;

    /**
     * @param params 查询条件
     * @return Result 沥青类技术要求分页列表
     * @Title: page
     * @Description: 沥青类技术要求分页列表
     */
    @GetMapping("page")
    public Result<IPage<LaboratoryMechanicsPressMachineDto>> page(@RequestParam Map<String, Object> params) {
        IPage<LaboratoryMechanicsPressMachineDto> page = service.page(params);
        return ResultUtils.ok(page);
    }

    /**
     * 设备数据上传
     */
    @PostMapping("/Upload")
    public Map<String, Object> Upload(@RequestBody JSONObject json) {
        Map<String, Object> resultMap = service.Upload(json);
        return resultMap;
    }

    /**
     * 设备数据上传
     */
    @PostMapping("/dataBaseUpload")
    public String dataBaseUpload(@RequestBody JSONObject json) {
        Integer key = null;
        JSONObject result = new JSONObject();
        try {
            String type = json.getString("deviceType");
            if ("W".equals(type)) {
                key = service.saveDataBaseUpload(json);
            } else if ("Y".equals(type)) {
                key = service.saveDataBaseUploadPress(json);
            } else if ("OUK".equals(type)) {
                key = service.saveDataBaseUploadOUKPress(json);
            } else if ("FYW".equals(type)) {
                key = service.saveDataBaseUploadFYAllPurpose(json);
            } else if ("TX2ZDWNJ".equals(type)) {//泰新二驻地欧凯万能机
                key = service.saveDataBaseUploadOKAllPurpose(json);
            } else if ("FYY".equals(type)) {
                key = service.saveDataBaseUploadFYYAllPurpose(json);
            } else if ("SWSB".equals(type)) {
                // 济微三标水稳拌合站数据采集
                key = service.saveDataBaseUploadSwBhzSb(json);
            } else if ("SWFB".equals(type)) {
                // 济微四标水稳拌合站数据采集
                key = service.saveDataBaseUploadSwBhzFb(json);
            } else if ("SWYB".equals(type)) {
                // 济微一标水稳拌合站数据采集
                key = service.saveDataBaseUploadSwBhzOb(json);
            } else if ("SWSBNEW".equals(type)) {
                // 济微三标水稳拌合站数据采集新
                key = service.saveDataBaseUploadSwBhzSbNew(json);
            } else if ("TX2BY".equals(type)) {
                //泰新2标压力机
                key = service.saveDataBaseUploadtx2bPress(json);
            } else if ("TX2BWNJ".equals(type)) {
                key = service.saveDataBaseUpload(json);
            } else if ("HTW".equals(type)) {
                //泰新1标万能机100/300,恒田软件   HT.mdb
                key = service.saveDataBaseUploadHT(json);
            } else if ("HTY".equals(type)) {
                //泰新总监办压力机,恒田软件   HT.mdb
                key = service.saveDataBaseUploadHTY(json);
            }
            else if ("JYKZKYJ".equals(type)) {
                //无锡建仪仪器  泰新3标抗压抗折机
                key = service.saveDataBaseUploadWXJY(json);
            } else if ("JYKZKYJZ".equals(type)) {
                //无锡建仪仪器  泰新3标抗压抗折机
                key = service.saveDataBaseUploadWXJYZ(json);
            } else if ("JYYLJ".equals(type)) {
                //无锡建仪仪器  泰新3标压力机
                key = service.saveDataBaseUploadWXJYYLJ(json);
            } else {
                result.put("code", 300);
                return result.toJSONString();
            }
            result.put("code", 200);
            result.put("data", key + "");
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 300);
            result.put("msgs", e.getMessage());
        }
        return result.toJSONString();
    }

    /**
     * 风行软件万能机设备数据上传，泰新三标300/600，齐临
     */
    @PostMapping("/fxdataBaseUpload")
    public String fxdataBaseUpload(@RequestBody JSONObject json) {
        Integer key = null;
        JSONObject result = new JSONObject();
        try {
            JSONObject universal = json.getJSONObject("universal");
            String type = universal.getString("deviceNum");
            if (StrUtil.isNotBlank(type)) {
                key = service.savefxDataBaseUpload(json);
                result.put("code", 200);
                result.put("data", key + "");
            } else {
                throw new RuntimeException();
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 300);
            result.put("msgs", e.getMessage());
        }
        return result.toJSONString();
    }


    /**
     * 风行软件压力机设备数据上传，齐临二标压力机 2000
     */
    @PostMapping("/fxyljdataBaseUpload")
    public String fxyljdataBaseUpload(@RequestBody JSONObject json) {
        Integer key = null;
        JSONObject result = new JSONObject();
        try {
            JSONObject universal = json.getJSONObject("universal");
            String type = universal.getString("deviceNum");
            if (StrUtil.isNotBlank(type)) {
                key = service.savefxYljDataBaseUpload(json);
                result.put("code", 200);
                result.put("data", key + "");
            } else {
                throw new RuntimeException();
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 300);
            result.put("msgs", e.getMessage());
        }
        return result.toJSONString();
    }

    @GetMapping("/test")
    public Result sendTest(@RequestParam Map<String, String> params) {
        service.sendTest(params);
        return ResultUtils.ok("ok");
    }

    /**
     * 沥青实验室数据接收（文双一分部沥青实验室）
     *
     * @param json
     * @return
     */
    @PostMapping("/dataBaseUploadForLqLab")
    public String dataBaseUploadForLqLab(@RequestBody JSONObject json) {
        Integer key = null;
        JSONObject result = new JSONObject();
        try {
            if ("WDD".equals(json.getString("deviceType"))) {
                // 稳定度

            } else if ("ZRD".equals(json.getString("deviceType"))) {
                // 针入度
                key = service.saveDataBaseUploadZrd(json);
            } else if ("RHD".equals(json.getString("deviceType"))) {
                // 软化点

            } else {
                result.put("code", 300);
                return result.toJSONString();
            }
            result.put("code", 200);
            result.put("data", key + "");
        } catch (Exception e) {
            result.put("code", 300);
        }
        return result.toJSONString();
    }


}
